layui.use(["element", "laytpl"], async function () {
    $ = layui.jquery;
    laytpl = layui.laytpl;
    refreshAll();
    onLayuiInit();
});

function refreshAll() {
    screenArr.map(async (item, index) => {
        //如果没有配置templet,使用默认值
        let {modelId, templet = normalChartBody} = item;
        item.renderInfo = item.renderInfo || renderInfo;
        let config;
        if (modelId) {
            config = await reqConfigure(modelId, item);
            //从后端获取title配置
            item.title = config.reqConfig.modelName;
        }
        laytpl(templet).render(item, function (html) {
            let parent = $(`td:eq(${index})>div`);
            //渲染模板内容
            parent.html(html);
            renderItem(parent, item, config);

        });
    });
}

function renderItem(parent, item, config) {
    //如果配置了data-model属性,则直接按chart模块渲染
    parent.find("[data-model]").each(async function () {
        if (!config) {
            config = await reqConfigure(this.getAttribute("data-model"), item);
        }
        renderBy(config, this);
    });
    //否则,按html渲染
    parent.find(".normal-chart-body").each(function () {
        if (!($(this).find("[data-model]").length)) {
            renderText(item);//如果没有配置modle信息,适应前端方式需要渲染文本,
        }
    });
}